/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminJFrame.java
 *
 * 
 */
package course;

//import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * 
 */
public class AdminJFrame extends javax.swing.JFrame implements WindowListener, ActionListener {

    private static final String UPDATE_CMD = "update";
    private MyDatabaseHandler db;

    /** Creates new form AdminJFrame */
    public AdminJFrame(MyDatabaseHandler db) {
        super("Form for Administrator");
        this.db = db;
        initComponents();
        //initDatabase();

    }

    /**
     * The action performed method is where you will end up when the button is clicked
     * @param e the event
     */
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals(UPDATE_CMD)) {
            db.setCode(jTextField1.getText());

        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jTextField11 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jTextField12 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel1.setForeground(new java.awt.Color(204, 0, 204));
        jLabel1.setLabelFor(jTextField1);
        jLabel1.setText("Code:");
        jLabel1.setName("codeLabel"); // NOI18N

        jTextField1.setName(""); // NOI18N
        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton1.setForeground(new java.awt.Color(255, 0, 255));
        jButton1.setText("Add");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel2.setForeground(new java.awt.Color(204, 0, 204));
        jLabel2.setText("Course Name:");

        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel3.setForeground(new java.awt.Color(204, 0, 204));
        jLabel3.setText("Education Area:");

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel4.setForeground(new java.awt.Color(204, 0, 204));
        jLabel4.setText("Course Type:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel5.setForeground(new java.awt.Color(204, 0, 204));
        jLabel5.setText("HP Points:");

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });

        jButton2.setForeground(new java.awt.Color(255, 0, 255));
        jButton2.setText("Search");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextPane1.setBackground(new java.awt.Color(255, 153, 255));
        jTextPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jTextPane1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        jTextPane1.setText("Course Database");
        jScrollPane1.setViewportView(jTextPane1);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel6.setForeground(new java.awt.Color(204, 0, 204));
        jLabel6.setText("Application Code:");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setForeground(new java.awt.Color(204, 0, 204));
        jLabel7.setText("Semester:");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel8.setForeground(new java.awt.Color(204, 0, 204));
        jLabel8.setText("Teacher:");

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel9.setForeground(new java.awt.Color(204, 0, 204));
        jLabel9.setText("Start Date:");

        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });

        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });

        jTextField8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField8ActionPerformed(evt);
            }
        });

        jTextField9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField9ActionPerformed(evt);
            }
        });

        jTextField10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField10ActionPerformed(evt);
            }
        });

        jTextField11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField11ActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel10.setForeground(new java.awt.Color(204, 0, 204));
        jLabel10.setText("Program Name:");

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel11.setForeground(new java.awt.Color(204, 0, 204));
        jLabel11.setText("Education Year:");

        jTextField12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField12ActionPerformed(evt);
            }
        });

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/myImage/teacher.jpg"))); // NOI18N

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel12.setForeground(new java.awt.Color(204, 0, 204));
        jLabel12.setText("App Code:");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(255, 0, 204));
        jLabel14.setText("Admin");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel9)
                    .addComponent(jLabel11)
                    .addComponent(jLabel10)
                    .addComponent(jLabel12)
                    .addComponent(jLabel6))
                .addGap(101, 101, 101)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField4, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jTextField9, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addComponent(jTextField8)
                        .addComponent(jTextField7)
                        .addComponent(jTextField6, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addComponent(jTextField5, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addComponent(jTextField10, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addComponent(jTextField11, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                        .addComponent(jTextField12, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(35, 35, 35))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(50, 50, 50)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton2)
                                .addGap(48, 48, 48)
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(46, 46, 46))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel14)
                        .addGap(106, 106, 106))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(45, 45, 45)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jButton2)
                    .addComponent(jButton1))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(89, 89, 89)
                        .addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel14)))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        //System.out.println("Kli");
        db.addCourse(jTextField1.getText(), jTextField2.getText(), jTextField3.getText(), jTextField4.getText(), Double.parseDouble(jTextField5.getText()));

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        Date today = null;
        try {
            today = df.parse(jTextField9.getText());
            //    System.out.println("Today = " + df.format(today));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        db.addOccation(jTextField6.getText(), jTextField7.getText(), jTextField8.getText(), today);
        db.addProgram(jTextField10.getText(), jTextField11.getText());
        //   db.addProgram_has_course(jTextField12.getText()jTextField10.getText(),jTextField12.getText());

        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed
public void searchCode(){
    ArrayList<Course> courseList = new ArrayList<Course>();
        courseList = db.getCourse();
        for (int i = 0; i < courseList.size(); i++) {
            if (jTextField1.getText().equals(courseList.get(i).getCode())) {
                jTextField2.setText(courseList.get(i).getCourseName());
                jTextField3.setText(courseList.get(i).getEducationArea());
                jTextField4.setText(courseList.get(i).getCourseType());
                jTextField5.setText(String.valueOf(courseList.get(i).getHpPoints()));
            }
        }
        //* Skriv en metod i DB handler för att hämta code/app code till lista
        //* kalla på metoden spara listan i xList
        //* for-sats som går igenom xList
        // if-sats i for-sats som kollar om jTextField1 = code i xList
        //  om ja sätt appCode = app code från xlist på plats i

        String appCode = "";
        ArrayList<Occation_has_Course> Occation_has_CourseList = new ArrayList<Occation_has_Course>();
        Occation_has_CourseList = db.getOccation_has_Course();
        for (int i = 0; i < Occation_has_CourseList.size(); i++) {
            if (jTextField1.getText().equals(Occation_has_CourseList.get(i).getCode())) {
                appCode = Occation_has_CourseList.get(i).getApplicationCode();
            }
        }

        ArrayList<Occation> occationList = new ArrayList<Occation>();
        occationList = db.getOccation();
        for (int i = 0; i < occationList.size(); i++) {
            if (appCode.equals(occationList.get(i).getApplicationCode())) {
                jTextField6.setText(occationList.get(i).getApplicationCode());
                jTextField7.setText(occationList.get(i).getSemester());
                jTextField8.setText(occationList.get(i).getTeacher());
                jTextField9.setText(String.valueOf(occationList.get(i).getStartDate()));
            }
        }

        String progCode = "";
        ArrayList<Program_has_Course> Program_has_CourseList = new ArrayList<Program_has_Course>();
        Program_has_CourseList = db.getProgram_has_Course();
        for (int i = 0; i < Program_has_CourseList.size(); i++) {
            if (jTextField1.getText().equals(Program_has_CourseList.get(i).getCode())) {
                progCode = Program_has_CourseList.get(i).getAppCode();
                jTextField12.setText(String.valueOf(Program_has_CourseList.get(i).getEducationYear()));
            }
        }

        ArrayList<Program> programList = new ArrayList<Program>();
        programList = db.getProgram();
        for (int i = 0; i < programList.size(); i++) {
            if (progCode.equals(programList.get(i).getAppCode())) {
                jTextField10.setText(programList.get(i).getAppCode());
                jTextField11.setText(programList.get(i).getProgramName());
            }
        }

}
public void searchAppCode(){
        ArrayList<Program> programList = new ArrayList<Program>();
        programList = db.getProgram();
        for (int i = 0; i < programList.size(); i++) {
            if (jTextField10.getText().equals(programList.get(i).getAppCode())) {
                //jTextField10.setText(programList.get(i).getAppCode());
                jTextField11.setText(programList.get(i).getProgramName());
            }
        }
          String progCode = "";
        ArrayList<Program_has_Course> Program_has_CourseList = new ArrayList<Program_has_Course>();
        Program_has_CourseList = db.getProgram_has_Course();
        for (int i = 0; i < Program_has_CourseList.size(); i++) {
            if (jTextField10.getText().equals(Program_has_CourseList.get(i).getAppCode())) {
                progCode = Program_has_CourseList.get(i).getCode();
                jTextField12.setText(String.valueOf(Program_has_CourseList.get(i).getEducationYear()));
            }
        }
           ArrayList<Course> courseList = new ArrayList<Course>();
        courseList = db.getCourse();
        for (int i = 0; i < courseList.size(); i++) {
            if (progCode.equals(courseList.get(i).getCode())) {
                jTextField1.setText(courseList.get(i).getCode());
                jTextField2.setText(courseList.get(i).getCourseName());
                jTextField3.setText(courseList.get(i).getEducationArea());
                jTextField4.setText(courseList.get(i).getCourseType());
                jTextField5.setText(String.valueOf(courseList.get(i).getHpPoints()));
            }
        }
         String appCode = "";
        ArrayList<Occation_has_Course> Occation_has_CourseList = new ArrayList<Occation_has_Course>();
        Occation_has_CourseList = db.getOccation_has_Course();
        for (int i = 0; i < Occation_has_CourseList.size(); i++) {
            if (jTextField10.getText().equals(Occation_has_CourseList.get(i).getCode())) {
                appCode = Occation_has_CourseList.get(i).getApplicationCode();
            }
        }

        ArrayList<Occation> occationList = new ArrayList<Occation>();
        occationList = db.getOccation();
        for (int i = 0; i < occationList.size(); i++) {
            if (appCode.equals(occationList.get(i).getApplicationCode())) {
                jTextField6.setText(occationList.get(i).getApplicationCode());
                jTextField7.setText(occationList.get(i).getSemester());
                jTextField8.setText(occationList.get(i).getTeacher());
                jTextField9.setText(String.valueOf(occationList.get(i).getStartDate()));
            }
        }
}

public void searchApplicationCode(){

// sök knapp för Application Code

        ArrayList<Occation> occationList = new ArrayList<Occation>();
        occationList = db.getOccation();
        for (int i = 0; i < occationList.size(); i++) {
            if (jTextField6.getText().equals(occationList.get(i).getApplicationCode())) {
                jTextField7.setText(occationList.get(i).getSemester());
                jTextField8.setText(occationList.get(i).getTeacher());
                jTextField9.setText(String.valueOf(occationList.get(i).getStartDate()));
            }
        }
         String appCode = "";
        ArrayList<Occation_has_Course> Occation_has_CourseList = new ArrayList<Occation_has_Course>();
        Occation_has_CourseList = db.getOccation_has_Course();
        for (int i = 0; i < Occation_has_CourseList.size(); i++) {
            if (jTextField6.getText().equals(Occation_has_CourseList.get(i).getApplicationCode())) {
                appCode = Occation_has_CourseList.get(i).getApplicationCode();
            }
        }
 ArrayList<Course> courseList = new ArrayList<Course>();
        courseList = db.getCourse();
        for (int i = 0; i < courseList.size(); i++) {
            if (appCode.equals(courseList.get(i).getCode())) {
                jTextField1.setText(courseList.get(i).getCode());
                jTextField2.setText(courseList.get(i).getCourseName());
                jTextField3.setText(courseList.get(i).getEducationArea());
                jTextField4.setText(courseList.get(i).getCourseType());
                jTextField5.setText(String.valueOf(courseList.get(i).getHpPoints()));
            }
        }
        String progCode = "";
        ArrayList<Program_has_Course> Program_has_CourseList = new ArrayList<Program_has_Course>();
        Program_has_CourseList = db.getProgram_has_Course();
        for (int i = 0; i < Program_has_CourseList.size(); i++) {
            if (jTextField6.getText().equals(Program_has_CourseList.get(i).getAppCode())) {
                progCode = Program_has_CourseList.get(i).getCode();
                jTextField12.setText(String.valueOf(Program_has_CourseList.get(i).getEducationYear()));
            }
        }

        ArrayList<Program> programList = new ArrayList<Program>();
        programList = db.getProgram();
        for (int i = 0; i < programList.size(); i++) {
            if (progCode.equals(programList.get(i).getAppCode())) {
                jTextField10.setText(programList.get(i).getAppCode());
                jTextField11.setText(programList.get(i).getProgramName());
            }
        }

}


    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

if (!jTextField1.getText().equals("")){
    searchCode();

} else if(!jTextField6.getText().equals("")){
    searchApplicationCode();

}
    
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField8ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField8ActionPerformed

    private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField9ActionPerformed

    private void jTextField10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField10ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField10ActionPerformed

    private void jTextField11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField11ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField11ActionPerformed

    private void jTextField12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField12ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField12ActionPerformed
    /**
     * @param args the command line arguments
     */
    /*public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new AdminJFrame().setVisible(true);
    }
    });
    }*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField11;
    private javax.swing.JTextField jTextField12;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

    public void windowOpened(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosing(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosed(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowIconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeiconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowActivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeactivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
